<!DOCTYPE html>
<html class="ui-page-login">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title></title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/style.css" rel="stylesheet" />
		<style>
			.area {
				margin: 20px auto 0px auto;
			}
			
			.mui-input-group:first-child {
				margin-top: 20px;
			}
			
			.mui-input-group label {
				width: 22%;
			}
			
			.mui-input-row label~input,
			.mui-input-row label~select,
			.mui-input-row label~textarea {
				width: 78%;
			}
			
			.mui-checkbox input[type=checkbox],
			.mui-radio input[type=radio] {
				top: 6px;
			}
			
			.mui-content-padded {
				margin-top: 25px;
			}
			
			.mui-btn {
				padding: 10px;
			}
			
			.mui-input-row label~input,
			.mui-input-row label~select,
			.mui-input-row label~textarea {
				margin-top: 1px;
			}
			
			.mui-control-content {
				background-color: white;
				min-height: 500px;
			}
			
			#sliderSegmentedControl {
				border: 0px;
			}
			
			label {
				font-size: 18px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">找回密码</h1>
		</header>
		<div class="mui-content">
			<div id="slider" class="mui-slider">
				<div id="sliderSegmentedControl" class="mui-slider-indicator mui-segmented-control">
					<a class="mui-control-item" href="#item1mobile">
						邮箱
					</a>
					<a class="mui-control-item" href="#item2mobile">
						手机号
					</a>
				</div>
				<div id="sliderProgressBar" class="mui-slider-progress-bar mui-col-xs-4"></div>
				<div class="mui-slider-group">
					<div id="item1mobile" class="mui-slider-item mui-control-content mui-active">
						<div id="scroll1" class="mui-scroll-wrapper">
							<div class="mui-scroll">
								<form class="mui-input-group">
									<div class="mui-input-row">
										<label>邮箱:</label>
										<input id='email' type="email" class="mui-input-clear mui-input" placeholder="请输入注册邮箱">
									</div>
								</form>
								<div class="mui-content-padded">
									<button value="0" id='sendMail' class="mui-btn mui-btn-block mui-btn-primary">提交</button>
								</div>
							</div>
						</div>
					</div>
					<div id="item2mobile" class="mui-slider-item mui-control-content">
						<div id="scroll2" class="mui-scroll-wrapper">
							<div class="mui-scroll">
								<form class="mui-input-group">
									<div class="mui-input-row">
										<label>手机:</label>
										<input id='phone' type="text" class="mui-input-clear mui-input" placeholder="请输入注册手机号">
									</div>
								</form>
								<div class="mui-content-padded">
									<button value="1" id='sendPhone' class="mui-btn mui-btn-block mui-btn-primary">提交</button>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/app.js"></script>
		<script src="js/ipjs/ip.js"></script>
		<script src="js/constatnt/var.js"></script>
		<script src="js/myjs/localVarchar.js"></script>
		<script>
			//			(function($, doc) {
			//				$.init();
			//				$.plusReady(function() {
			//					var sendButton = doc.getElementById('sendMail');
			//					var emailBox = doc.getElementById('email');
			//					sendButton.addEventListener('tap', function() {
			//						app.forgetPassword(emailBox.value, function(err, info) {
			//							plus.nativeUI.toast(err || info);
			//						});
			//					}, false);
			//				});
			//			}(mui, document));

			/**
			 * 邮箱发送
			 */
			document.getElementById("sendMail").addEventListener('tap', function() {
				var email = document.getElementById("email").value;
				if(checkEmail(email) && email != "" && email != null) {
					sendMsg(0, email);
				} else {
					alert("邮箱格式错误");
				}
			})

			/**
			 * 手机号发送
			 */
			document.getElementById("sendPhone").addEventListener('tap', function() {
				var phone = document.getElementById("phone").value;
				if(istel(phone) && phone != "" && phone != null) {
					sendMsg(1, phone);
				} else {
					alert("手机号格式错误");
				}
			})

			function sendMsg(style, contact) {
				mui.ajax(ip + '/search/findPassword/' + style + '/' + contact, {
					type: 'get',
					timeout: 10000,
					success: function(data) {
						alert(data.data.object);
						//服务器返回响应，根据响应结果，分析是否登录成功；
						if(data.data.code === OPERATION_FAIL) {

						} else if(data.data.code == CODE_ERROR) {

						} else if(data.data.code == CODE_SUCCESS) {
							var webview = mui.openWindow({
								url: 'setPassword.html',
								id: 'setPassword',
								extras: {
									idValue: contact
								}
							});
						}
					},
					error: function(xhr, type, errorThrown) {
						//异常处理；
						mui.toast("系统异常！");
					}
				});
			}

			function checkEmail(myemail) {　　　
				var myReg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
				if(myReg.test(myemail)) {　　　　
					return true;　　
				} else {　　　　
					return false;
				}
			}

			function istel(tel) {
				var rtn = false;
				//移动号段
				var regtel = /^((13[4-9])|(15([0-2]|[7-9]))|(18[2|3|4|7|8])|(178)|(147))[\d]{8}$/;
				if(regtel.test(tel)) {
					rtn = true;
				}
				//电信号段
				regtel = /^((133)|(153)|(18[0|1|9])|(177))[\d]{8}$/;
				if(regtel.test(tel)) {
					rtn = true;
				}
				//联通号段
				regtel = /^((13[0-2])|(145)|(15[5-6])|(176)|(18[5-6]))[\d]{8}$/;
				if(regtel.test(tel)) {
					rtn = true;
				}
				return rtn;
			}
		</script>
	</body>

</html>